package com.chengh.nami.web.controller.system.log;

import com.chengh.nami.common.request.PageQuery;
import com.chengh.nami.common.response.PageData;
import com.chengh.nami.common.response.R;
import com.chengh.nami.system.domain.dto.OperLogDto;
import com.chengh.nami.system.pojo.SysOperLog;
import com.chengh.nami.system.service.ISysOperLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@RequestMapping("/system/log/operLog")
@RequiredArgsConstructor
@Tag(name = "OperLogController", description = "操作日志管理")
public class OperLogController {


    private final ISysOperLogService operLogService;

    /**
     * 获取操作日志列表
     *
     * @return 登录日志信息
     */
    @GetMapping("/list")
    @Operation(summary = "获取所有的用户登录日志", description = "")
    public R<PageData<SysOperLog>> list(OperLogDto operLogDto, PageQuery pageQuery) {
        PageData<SysOperLog> opesLogs = operLogService.getList(operLogDto, pageQuery);
        return R.ok(opesLogs);
    }

    /**
     * 清空操作日志
     *
     * @return 是否成功
     */
    @DeleteMapping("/cleanOperLog")
    @Operation(summary = "清除操作日志", description = "")
    public R<Void> cleanOperLog() {
        operLogService.cleanOperLog();
        return R.ok();
    }

    @PostMapping("/export")
    @Operation(summary = "导出文件", description = "")
    public void export(HttpServletResponse response, OperLogDto operLogDto, PageQuery pageQuery) {
        operLogService.exportLogininforExcle(response, operLogDto, pageQuery);
    }
}
